﻿namespace Calculator
{
    public class CalculatorC
    {
        // 属性
        private double num1;
        private double num2;
        public double Num1 { get => num1; set => num1 = value; }
        public double Num2 { get => num2; set => num2 = value; }

        public CalculatorC()
        {
            Num1 = 0;
            Num2 = 0;
        }
        public CalculatorC(double num1, double num2)
        {
            Num1 = num1;
            Num2 = num2;
        }

        public double GetResult(string s)
        {
            double result = 0;
            switch (s)
            {
                case "+": result = Num1 + Num2; break;
                case "-": result = Num1 - Num2; break;
                case "*": result = Num1 * Num2; break;
                case "/":
                    if (Num2 == 0)
                        throw new Exception("除数不能为0！");
                    else
                        result = Num1 / Num2; break;
                default: break;
            }
            return result;
        }

    }
}